<?php

/**
 * SocialEngine
 *
 * @category   Application_Extensions
 * @package    Sitealbum
 * @copyright  Copyright 2010-2011 BigStep Technologies Pvt. Ltd.
 * @license    http://www.socialengineaddons.com/license/
 * @version    $Id: light-box-view.tpl 2011-08-026 9:40:21Z SocialEngineAddOns $
 * @author     SocialEngineAddOns
 */
?>
<div>
<?php if(empty($this->isajax)): ?>
 <div class="photo_lightbox_options">
    <a onclick = "closeLightBoxAlbum();" class="close" title="<?php echo $this->translate('Close');?>" ></a>
</div>
<div id="ads_hidden" style="display: none;" >
  <?php echo $this->content()->renderWidget("sitealbum.lightbox-ads", array('limit' => 1)) ?>
</div>
<div id='image_div_album'>
<?php endif; ?>
<?php
  $showLink = false;
  if (isset($this->params['type']) && !empty($this->params['type'])):
    if ($this->type_count > 1):
      $showLink = true;
    endif;
  elseif ($this->album->count() > 1):
    $showLink = true;
  endif;
?>
   <?php if($showLink):?>
   <div class="photo_lightbox_options" id="sitealbum_photo_scroll">
     <a onclick="photopaginationSitealbum('<?php echo $this->escape(Engine_Api::_()->sitealbum()->getLightBoxPhotoHref($this->prevPhoto,array_merge($this->params, array('offset'=>$this->PrevOffset)))) ?>' )" class="pre" title="<?php echo $this->translate('Previous');?>" ></a>
		<a onclick="photopaginationSitealbum('<?php echo $this->escape(Engine_Api::_()->sitealbum()->getLightBoxPhotoHref($this->nextPhoto,array_merge($this->params, array('offset'=>$this->NextOffset)))) ?>')" class="nxt" title="<?php echo $this->translate('Next');?>" ></a>
   </div>
   <?php endif; ?>
  	<div class="photo_lightbox_photo_detail sitealbum_lightbox_photo_detail" id="photo_lightbox_photo_detail">
      <?php if(isset($this->params['type']) && !empty ($this->params['type'])):?>    
      <b><?php echo $this->translate('%1$s', ucfirst($this->displayTitle));?></b>        
    <br />
     <?php echo $this->translate('%1$s By %2$s',  $this->htmlLink($this->album, $this->album->getTitle()),$this->album->getOwner()->__toString()); ?>
    <?php else: ?>
     <?php echo $this->translate('%1$s By %2$s',  $this->htmlLink($this->album, $this->album->getTitle()),$this->album->getOwner()->__toString()); ?>
		|
     <?php echo $this->translate('Photo %1$s of %2$s',
          $this->locale()->toNumber($this->getPhotoIndex + 1),
          $this->locale()->toNumber($this->album->count())) ?>
     <?php endif;?>
	 </div>  
 <div class="photo_lightbox_image_content sitealbum_lightbox_image_content">
  	<div id='media_image_div_sitealbum' class="photo_lightbox_image_content_media">
      <?php if($this->viewPermission): ?>      
      <a id='media_photo_next' <?php if ($showLink): ?> onclick="photopaginationSitealbum('<?php echo $this->escape(Engine_Api::_()->sitealbum()->getLightBoxPhotoHref($this->nextPhoto,array_merge($this->params, array('offset'=>$this->NextOffset)))) ?>')" <?php endif; ?> >
      <?php echo $this->htmlImage($this->photo->getPhotoUrl(), $this->photo->getTitle(), array(
          'id' => 'media_photo',
          'class'=>"lightbox_photo"
        )); ?>     
      </a>      
      <?php else:?>
        <div class="tip">
          <span><?php echo $this->translate('You do not have the permission to view this photo.');?> </span>
        </div>
     <?php endif; ?>
    </div>
   </div>
<?php if($this->viewPermission): ?>
  <?php $viewer_id=$this->viewer()->getIdentity();
      if($this->canComment):?>
   <div class="photo_lightbox_user_options sitealbum_lightbox_user_options" id="photo_lightbox_user_options">
    <a id="<?php echo $this->subject()->getType() ?>like_link" <?php if( $this->subject()->likes()->isLike($this->viewer()) ): ?>style="display: none;" <?php endif; ?>onclick="en4.sitealbum.likes.like('<?php echo $this->subject()->getType() ?>', '<?php echo $this->subject()->getIdentity() ?>');" href="javascript:void(0);" class="photo_lightbox_like" title="<?php echo $this->translate('Like This');?>"><?php echo $this->translate('Like');?></a>
    <a id="<?php echo $this->subject()->getType() ?>unlike_link" <?php if( !$this->subject()->likes()->isLike($this->viewer()) ): ?>style="display:none;" <?php endif;?> onclick="en4.sitealbum.likes.unlike('<?php echo $this->subject()->getType() ?>', '<?php echo $this->subject()->getIdentity() ?>');" href="javascript:void(0);" class="photo_lightbox_unlike" title="<?php echo $this->translate('Unlike This');?>"><?php echo $this->translate('Unlike');?></a>
    <a href="javascript:void(0);" onclick="$('comment-form').style.display = '';$('comment-form').body.focus();" class="photo_lightbox_comment" title="<?php echo $this->translate('Post Comment');?>" ><?php echo $this->translate('Comments');?></a>
  </div>
  <?php endif;?>
  <?php if( $this->canEdit ): ?>
    <div class="photo_lightbox_user_right_options sitealbum_lightbox_user_right_options" id="photo_lightbox_user_right_options">
      <a class="icon_photos_lightbox_rotate_ccw"  onclick="$(this).set('class', 'icon_loading'); en4.sitealbum.rotate(<?php echo $this->photo->getIdentity() ?>, 90).addEvent('complete', function(){ this.set('class', 'icon_photos_lightbox_rotate_ccw') }.bind(this));loadingImageSitealbum(); " title="<?php echo $this->translate("Rotate Left"); ?>" ></a>
      <a class="icon_photos_lightbox_rotate_cw" onclick="$(this).set('class', 'icon_loading'); en4.sitealbum.rotate(<?php echo $this->photo->getIdentity() ?>, 270).addEvent('complete', function(){ this.set('class', 'icon_photos_lightbox_rotate_cw') }.bind(this)); loadingImageSitealbum();" title="<?php echo $this->translate("Rotate Right"); ?>" ></a>
      <a class="icon_photos_lightbox_flip_horizontal" onclick="$(this).set('class', 'icon_loading'); en4.sitealbum.flip(<?php echo $this->photo->getIdentity() ?>, 'horizontal').addEvent('complete', function(){ this.set('class', 'icon_photos_lightbox_flip_horizontal') }.bind(this)); loadingImageSitealbum();" title="<?php echo $this->translate("Flip Horizontal"); ?>" ></a>
      <a class="icon_photos_lightbox_flip_vertical"  onclick="$(this).set('class', 'icon_loading'); en4.sitealbum.flip(<?php echo $this->photo->getIdentity() ?>, 'vertical').addEvent('complete', function(){ this.set('class', 'icon_photos_lightbox_flip_vertical') }.bind(this)); loadingImageSitealbum();" title="<?php echo $this->translate("Flip Vertical"); ?>"></a>
    </div>
  <?php endif ?>
   <?php if ($this->canMakeFeatured && !$this->allowView): ?>
        <div class="tip">
          <span>
            <?php echo $this->translate("SITEALBUM_PHOTO_VIEW_PRIVACY_MESSAGE"); ?>
          </span>
        </div>
      <?php endif; ?>
  <div class="photo_lightbox_content" > 
    <div id="photo_lightbox_text">
      <div class="photo_lightbox_content_left">
				<div class="photo_detail">
	        <span class="owner">
	         <?php
	          echo $this->translate('By %1$s',
	          $this->htmlLink($this->photo->getOwner()->getHref(),$this->photo->getOwner()->getTitle()));
	        	?>
	        	| <?php echo $this->timestamp($this->photo->modified_date) ?>
	        </span>
	      </div>
	      <div class="photo_options">
          <?php if( $this->canTag ): ?>
         	<a href='javascript:void(0);' onclick='taggerInstanceSitealbum.begin();'><?php echo $this->translate('Tag This Photo');?></a>
           <?php endif; ?>

         	<?php if ( !empty ($viewer_id)): ?>
          <a href="javascript:void(0);" onclick="showSmoothBox('<?php echo $this->escape($this->url(array('module'=> 'activity', 'controller' => 'index', 'action' => 'share','type' => 'album_photo', 'id' => $this->photo->getIdentity(), 'format' => 'smoothbox'), 'default' , true)); ?>'); return false;" >
             <?php echo $this->translate("Share") ?>
           </a>
          <a href="javascript:void(0);" onclick="showSmoothBox('<?php echo ($this->url(array('module'=> 'core', 'controller' => 'report', 'action' => 'create',  'subject' => $this->photo->getGuid(), 'format' => 'smoothbox'), 'default' , true)); ?>'); return false;" >
           <?php echo $this->translate("Report") ?>
           </a>
           <?php if( Engine_Api::_()->sitealbum()->canMakeProfilePhoto() ):?>
           <a href="<?php echo $this->url(array('controller' => 'edit', 'action' => 'external-photo', 'photo' => $this->photo->getGuid(), 'format' => 'smoothbox'), 'user_extended' , true); ?>" onclick="showSmoothBox('<?php echo $this->escape($this->url(Array('controller' => 'edit', 'action' => 'external-photo', 'photo' => $this->photo->getGuid(), 'format' => 'smoothbox'), 'user_extended' , true)); ?>'); return false;" > <?php echo $this->translate("Make Profile Photo") ?></a>
            <?php endif; ?>
           <?php endif; ?>
            <?php if( Engine_Api::_()->sitealbum()->canDownloadPhoto() ):?>
						 <iframe src="about:blank" style="display:none" name="downloadframe"></iframe>
            <a href="<?php echo $this->url(array('module' => 'socialengineaddon', 'controller' => 'core', 'action' => 'download'), 'default', true); ?><?php echo '?path=' . urlencode($this->photo->getPhotoUrl()) ?>" target='downloadframe'><?php echo $this->translate('Download')?></a>
             <?php endif; ?>
           <?php if( $this->canMakeFeatured && $this->allowView ): ?>           
            <?php echo $this->htmlLink('javascript:void(0);', $this->translate('Make Photo of the Day'), array('onclick'=>"showSmoothBox('".$this->escape($this->url(array('controller'=>'photo','action' => 'add-photo-of-day','photo_id'=>$this->subject()->getIdentity()),'sitealbum_extended',true))."'); return false;")) ?>
            <a href="javascript:void(0);"  onclick='featuredPhoto();'><span id="featured_sitealbum_photo" <?php if($this->subject()->featured): ?> style="display:none;" <?php endif;?> title="<?php echo $this->translate("Make Featured"); ?>" ><?php echo $this->translate("Make Featured"); ?> </span> <span id="un_featured_sitealbum_photo" <?php if(!$this->subject()->featured): ?> style="display:none;" <?php endif;?> title="<?php echo $this->translate("Make Un-Featured"); ?>" > <?php echo $this->translate("Make Un-featured"); ?> </span></a>           
          <?php endif;?>
          <?php if( $this->canDelete ): ?>

          <?php
           if (!Engine_Api::_()->sitealbum()->isLessThan417AlbumModule()):
          echo $this->htmlLink(array('route' => 'album_extended','controller'=>'photo', 'action' => 'delete','album_id'=>$this->photo->album_id,'photo_id'=>$this->photo->getIdentity()), $this->translate('Delete'), array('onclick'=>"showSmoothBox('".$this->escape($this->url(array('controller'=>'photo', 'action' => 'delete','album_id'=>$this->photo->album_id,'photo_id'=>$this->photo->getIdentity()),'album_extended',true))."'); return false;"));
           else:
          echo $this->htmlLink(array('route' => 'album_extended','controller'=>'photo', 'action' => 'delete','album_id'=>$this->photo->collection_id,'photo_id'=>$this->photo->getIdentity()), $this->translate('Delete'), array('onclick'=>"showSmoothBox('".$this->escape($this->url(array('controller'=>'photo', 'action' => 'delete','album_id'=>$this->photo->collection_id,'photo_id'=>$this->photo->getIdentity()),'album_extended',true))."'); return false;"));
             endif;?>

        <?php endif; ?>
        </div>
      </div>
      <div class="photo_lightbox_content_middle">
        <div class="photo_lightbox_photo_tags" id="media_tags" style="display: none;">
          <?php echo $this->translate('In this photo:'); ?>
        </div>
         <?php if($this->canEdit  || !empty($this->photo->description)  ): ?>
        <div class="photo_lightbox_photo_description widthfull" id="link_sitealbum_description" style="display:block;">
          <?php if($this->canEdit): ?>
            <span class="lightbox_photo_description_edit_icon">
              <a href="javascript:void(0);" onclick="showeditDescription()" title=" <?php echo $this->translate('Edit this caption');?> "></a>
            </span>
          <?php endif; ?>
          <span id="sitealbum_description" class="lightbox_photo_description">
            <?php if (!empty($this->photo->description) ): ?>
              <?php echo $this->photo->getDescription() ?>
            <?php elseif($this->canEdit): ?>
              <a href="javascript:void(0);" onclick="showeditDescription()" >  <?php echo $this->translate('Add a caption');?> </a>
            <?php endif; ?>
          </span>
        </div>
         <?php endif; ?>
        <div class="photo_lightbox_photo_description"  >
          <div id="edit_sitealbum_description" style="display: none;">
             <textarea rows="2" cols="10"  name="edit_description" id="editor_sitealbum_description" title="<?php echo $this->translate('Add a caption');?>" ><?php echo $this->photo->description; ?></textarea>
            <div>
              <button name="save" onclick="saveeditDescription()"><?php echo $this->translate('Save'); ?></button>
              <button name="cancel" onclick="showeditDescription();"><?php echo $this->translate('Cancel'); ?></button>
            </div>
          </div>
          <div id="sitealbum_description_loading" style="display: none;" >
            <center><img src='application/modules/Socialengineaddon/externals/images/icons/loader.gif'   /></center>
          </div>
        </div>
        <div id="photo_view_comment" >
          <?php echo $this->action("list", "comment", "core", array("type"=>"album_photo", "id"=>$this->photo->getIdentity())); ?>
        </div>
      </div>
      <div class="photo_lightbox_content_right" id="ads">     
      </div>
    </div>
 	</div>
  <?php endif;?>
<?php if(empty($this->isajax)): ?>
	</div>
<?php endif; ?>
</div>

<script type="text/javascript">
var taggerInstanceSitealbum;
  if(window.parent.defaultLoad)
  window.parent.defaultLoad=false;
en4.core.runonce.add(function() {
  var descEls = $$('.albums_viewmedia_info_caption');
  if( descEls.length > 0 ) {
    descEls[0].enableLinks();
  }

  taggerInstanceSitealbum = new Tagger('media_photo_next', {
    'title' : '<?php echo $this->string()->escapeJavascript($this->translate('Tag This Photo')); ?>',
    'description' : '<?php echo $this->string()->escapeJavascript($this->translate('Type a tag or select a name from the list.')); ?>',
    'createRequestOptions' : {
      'url' : '<?php echo $this->url(array('module' => 'core', 'controller' => 'tag', 'action' => 'add'), 'default', true) ?>',
      'data' : {
        'subject' : '<?php echo $this->subject()->getGuid() ?>'
      }
    },
    'deleteRequestOptions' : {
      'url' : '<?php echo $this->url(array('module' => 'core', 'controller' => 'tag', 'action' => 'remove'), 'default', true) ?>',
      'data' : {
        'subject' : '<?php echo $this->subject()->getGuid() ?>'
      }
    },
    'cropOptions' : {
      'container' : $('media_photo_next')
    },
    'tagListElement' : 'media_tags',
    'existingTags' : <?php echo $this->action('retrieve', 'tag', 'core', array('sendNow' => false)) ?>,
    'suggestProto' : 'request.json',
    'suggestParam' : "<?php echo $this->url(array('module' => 'user', 'controller' => 'friends', 'action' => 'suggest', 'includeSelf' => true), 'default', true) ?>",
    'guid' : <?php echo ( $this->viewer()->getIdentity() ? "'" . $this->viewer()->getGuid() . "'" : 'false' ) ?>,
    'enableCreate' : <?php echo ( $this->canTag ? 'true' : 'false') ?>,
    'enableDelete' : <?php echo ( $this->canUntagGlobal ? 'true' : 'false') ?>
  });

  var onclickNext = $('media_photo_next').getProperty('onclick');
  taggerInstanceSitealbum.addEvents({
    'onBegin' : function() {
      $('media_photo_next').setProperty('onclick','');
    },
    'onEnd' : function() {
      $('media_photo_next').setProperty('onclick',onclickNext);
    }
  });

});

window.addEvent('keyup', function(e) {
  if( e.target.get('tag') == 'html' ||
    e.target.get('tag') == 'body' ||
    e.target.get('tag') == 'a') {
    if( e.key == 'right' ) {
      photopaginationSitealbum(getNextPhotoSitealbum());
    } else if( e.key == 'left' ) {
      photopaginationSitealbum(getPrevPhotoSitealbum());
    }
  }
});

function getPrevPhotoSitealbum(){
  return '<?php echo $this->escape(Engine_Api::_()->sitealbum()->getLightBoxPhotoHref($this->prevPhoto,array_merge($this->params, array('offset'=>$this->PrevOffset )))) ?>';
}
function getNextPhotoSitealbum(){
  return '<?php echo $this->escape(Engine_Api::_()->sitealbum()->getLightBoxPhotoHref($this->nextPhoto,array_merge($this->params, array('offset'=>$this->NextOffset)))) ?>';
}

var photopaginationSitealbum = function(url)
{ 
   if($('ads') && $('ads_hidden')){
     $('ads_hidden').innerHTML = $('ads').innerHTML;
    }
  var photoUrl=url.replace("/sitealbums/", "/albums/");
  photoUrl=photoUrl.replace("/light-box-view/album_id/", "/view/album_id/");
  if (history.pushState)
    history.pushState( {}, document.title, photoUrl );
  else{
    window.location.hash =photoUrl;
  }

  if(document.getElementById('photo_lightbox_photo_detail'))
    document.getElementById('photo_lightbox_photo_detail').style.display="none";
  setHtmlScroll("auto");
  setImageScrollAlbum("hidden");
  if(document.getElementById('page_lightbox_text'))
    document.getElementById('page_lightbox_text').style.display="none";
  if(document.getElementById('page_lightbox_user_options'))
    document.getElementById('page_lightbox_user_options').style.display="none";
  if(document.getElementById('page_lightbox_user_right_options'))
    document.getElementById('page_lightbox_user_right_options').style.display="none";
  if(document.getElementById('media_image_div_sitealbum'))
    document.getElementById('media_image_div_sitealbum').innerHTML="<img src='application/modules/Socialengineaddon/externals/images/icons/loader.gif'  class='lightbox_loader_img' />";

  en4.core.request.send(new Request.HTML({
    url : url,
    data : {
      format : 'html',
      isajax : 1
    },
    onSuccess : function(responseTree, responseElements, responseHTML, responseJavaScript) {
       setHtmlScroll("hidden");
       setImageScrollAlbum("auto");
      $('image_div_album').innerHTML = responseHTML;
        if($('ads') && $('ads_hidden')){
           $('ads').innerHTML =  $('ads_hidden').innerHTML;
           $('ads_hidden').innerHTML='';
       }
    }
  }));
};

function showSmoothBox(url)
{
  Smoothbox.open(url);
  parent.Smoothbox.close;
}

function photoLike(){

  en4.core.comments.like('<?php echo $this->subject()->getType() ?>', '<?php echo $this->subject()->getIdentity() ?>')
  document.getElementById('sitealbum_like').style.display="none";
  document.getElementById('sitealbum_unlike').style.display="block";
}

function photoUnlike(){
  en4.core.comments.unlike('<?php echo $this->subject()->getType() ?>', '<?php echo $this->subject()->getIdentity() ?>');
  document.getElementById('sitealbum_like').style.display="";
  document.getElementById('sitealbum_unlike').style.display="none";
}

function showeditDescription(){
  if(document.getElementById('edit_sitealbum_description')){
    if(document.getElementById('link_sitealbum_description').style.display=="block"){
      document.getElementById('link_sitealbum_description').style.display="none";
      document.getElementById('edit_sitealbum_description').style.display="block";
      $('editor_sitealbum_description').focus();
    }else{
      document.getElementById('link_sitealbum_description').style.display="block";
      document.getElementById('edit_sitealbum_description').style.display="none";
    }

    if(document.getElementById('sitealbum_description_loading'))
      document.getElementById('sitealbum_description_loading').style.display="none";
  }
}

function saveeditDescription()
{
  var photo_id = '<?php echo $this->photo->getIdentity(); ?>';
  var str =document.getElementById('editor_sitealbum_description').value.replace('/\n/g','<br />');
  var str_temp =document.getElementById('editor_sitealbum_description').value;
  
  if(document.getElementById('sitealbum_description_loading'))
  document.getElementById('sitealbum_description_loading').style.display="";

  document.getElementById('edit_sitealbum_description').style.display="none";
  en4.core.request.send(new Request.HTML({
    url :'<?php echo $this->url(array('module' => 'sitealbum', 'controller' => 'photo', 'action' => 'edit-description'), 'default', true) ?>',
    data : {
      format : 'html',
      text_string : str_temp,
      photo_id : photo_id
    },
    onSuccess : function(responseTree, responseElements, responseHTML, responseJavaScript) {

      if(str=='')
        str_temp='<a href="javascript:void(0);" onclick="showeditDescription()" >  <?php echo $this->string()->escapeJavascript($this->translate('Add a caption')); ?> </a>';
        document.getElementById('sitealbum_description').innerHTML=str_temp;
        showeditDescription();
      }
    }));
  }

var loadingImageSitealbum= function(){
     if(document.getElementById('media_image_div_sitealbum'))
		$('media_photo').src = "application/modules/Socialengineaddon/externals/images/icons/loader.gif";
      $('media_photo').style.marginTop='245px';
   
  };

</script>
<script type="text/javascript">
  function featuredPhoto()
  {
    en4.core.request.send(new Request.HTML({
      method : 'post',
      'url' : en4.core.baseUrl + 'sitealbum/photo/featured',
      'data' : {
        format : 'html',
        'subject' : '<?php echo $this->subject()->getGuid() ?>'
      },
      onSuccess : function(responseTree, responseElements, responseHTML, responseJavaScript) {
       if($('featured_sitealbum_photo').style.display=='none'){
        $('featured_sitealbum_photo').style.display="";
        $('un_featured_sitealbum_photo').style.display="none";
       }else{
          $('un_featured_sitealbum_photo').style.display="";
        $('featured_sitealbum_photo').style.display="none";
       }
      }
    }));

    return false;

  }
</script>
